#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int t, n, m, l, V, d[N], v[N], a[N], p[N];
int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    scanf("%d", &t);
    while (t--) {
        int ans = 0, maxn = 0;
        scanf("%d%d%d%d", &n, &m, &l, &V);
        for (int i = 1; i <= n; i++) {
            scanf("%d%d%d", &d[i], &v[i], &a[i]);
        }
        for (int i = 1; i <= m; i++) {
            scanf("%d", &p[i]);
            maxn = max(maxn, p[i]);
        }
        for (int i = 1; i <= n; i++) {
            if (maxn >= d[i] && V < v[i])ans++;
        }
        if (ans == 0)printf("%d %d\n", ans, m);
        else  printf("%d %d\n", ans, m - 1);
    }
    return 0;
}